﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;

namespace StarForce {
    public class AtlasData 
    {
        /// <summary>
        /// 图片缓存队列
        /// </summary>
        private Dictionary<string,Sprite> spriteDic = new Dictionary<string, Sprite>();
        private SpriteAtlas m_Atlas = null;
        public AtlasData(SpriteAtlas atlas) => m_Atlas = atlas; 

        /// <summary>
        /// 在缓存中获取图片
        /// </summary>
        /// <param name="spriteName"></param>
        /// <returns></returns>
        public Sprite GeSpriteByName(string spriteName) {
            Sprite sprite = null;
            spriteDic.TryGetValue(spriteName, out sprite);
            if (sprite == null) {
                sprite = m_Atlas.GetSprite(spriteName);
                if (sprite != null) {
                    spriteDic.Add(spriteName,sprite);
                }
            }
            return sprite;
        }
    }
}

